package cn.sxt.yjq.yxl.head;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.yjq.yxl.controller.BaseController;
import cn.sxt.yjq.yxl.pojo.AColumns;
import cn.sxt.yjq.yxl.pojo.AColumnsEnum;
import cn.sxt.yjq.yxl.pojo.AItems;
import cn.sxt.yjq.yxl.pojo.AItemsEnum;
import cn.sxt.yjq.yxl.service.IQuestionService;
import cn.sxt.yjq.yxl.util.ConstatFinalUtil;
import cn.sxt.yjq.yxl.util.PageInfoUtil;

@Controller
public class IndexHeadController extends BaseController
{
	@Resource
	private IQuestionService questionService;
	
	@RequestMapping("/main")
	public String main(){
		return "/head/main";
	}
	
	/*@RequestMapping("/{url}")
	public String itemList(HttpServletRequest request,@PathVariable String url ){
		ConstatFinalUtil.LOGGER.info("---- itemList --url:{}-- ---id:{}",url);
		Map<String, Object> condMap = new HashMap<String, Object>();
		 查询url对应的栏目 
		condMap.clear();
		condMap.put("url", url);
		AColumns columns = this.questionService.findOneColumnsService(condMap);
		request.setAttribute("columns", columns);
		 分页信息 
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		 查询url对应的栏目下面的测试项信息
		 * 启用 
		condMap.clear();
		condMap.put("status", AItemsEnum.STATUS_ENABLE.getStatus());
		condMap.put("columnsId", columns.getId());
		List<AItems> itemsList = this.questionService.findItemsCondListService(pageInfoUtil, condMap);
		 测试项列表 
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		request.setAttribute("itemsList", itemsList);
		return "/head/itemsList" ; 
	}*/
	/**
	 * 测试项的详情页
	 * @param request
	 * @param iid
	 * @return
	 */
	@RequestMapping("/items/{iid}")
	public String itemsInfo(HttpServletRequest request ,@PathVariable int iid)
	{
		ConstatFinalUtil.LOGGER.info("---- itemsInfo ----");
		/* 根据Id查询测试项 */
		Map<String, Object> condMap = new HashMap<String,Object>();
		condMap.clear();
		condMap.put("id", iid);
		AItems items = this.questionService.findOneItemsService(condMap);
		/* 将查询出的结果放到request */
		request.setAttribute("items", items);
		
		/* 查询上一条 */
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		/*pageInfoUtil.setPageSize(1);*/
		condMap.clear();
		condMap.put("pubTimeDa", items.getPubTime());
		condMap.put("orderby", "pubTimeASC");
		List<AItems> itemsPreList = this.questionService.findItemsCondListService(pageInfoUtil, condMap);
		request.setAttribute("itemsPreList", itemsPreList);
		
		/* 查询下一条 */
		condMap.clear();
		condMap.put("pubTimeXiao", items.getPubTime());
		List<AItems> itemsNextList = this.questionService.findItemsCondListService(pageInfoUtil, condMap);
		request.setAttribute("itemsNextList", itemsNextList);
		return "/head/itemsInfo" ; 
	}
	
	@RequestMapping("/header")
	public String header(HttpServletRequest request){
		ConstatFinalUtil.LOGGER.info("-------header-------");
		/*将所有的栏目查询出来*/
		Map<String, Object> condMap = new HashMap<String , Object>();
		/*
		 * 只查寻状态为启用的
		 */
		condMap.put("status", AColumnsEnum.STATUS_ENABLE.getStatus());
		List<AColumns> columnsList=this.questionService.findCondListColumnsService(null, condMap);
		request.setAttribute("columns", columnsList);
		return"/head/header";
	}
}

